<template>
	<view class="resetpwd_page">
		<view class="page_content">
			<u-form :model="form">
				<u-form-item prop="mobile" class="items">
					<u-input v-model="form.mobile" placeholder="请输入手机号" prefixIcon="phone" border="false"></u-input>
				</u-form-item>
				<u-form-item prop="code">
					<u-input v-model="form.code" placeholder="请输入验证码" prefixIcon="email" border="false">
						<template slot="suffix">
							<button class="code_btn" :disabled="dis" @click="getCode()">{{dis?`重新获取${wait}`:'获取验证码'}}</button>
						</template>
					</u-input>
				</u-form-item>
				<u-form-item prop="newpassword">
					<u-input password="true" v-model="form.newpassword" placeholder="请输入新密码" prefixIcon="lock" 
						border="false"></u-input>
				</u-form-item>
				<u-form-item>
					<u-input type="password" placeholder="再次输入新密码" v-model="form.newpassword1" prefixIcon="lock" border="false"></u-input>
				</u-form-item>
			</u-form>
			
		</view>
		<button class="sumbit_btn" @click="toResetPwd()">提交</button>
	</view>
</template>

<script>
	import { resetPwd } from "../../api/index.js"
	export default {
		data() {
			return {
				dis: false,
				wait: 60,
				form: {
					mobile: '',
					code: '',
					newpassword: '',
					newpassword1:''
				}
			}
		},
		methods: {
			toResetPwd(){
				let data = {
					mobile:this.form.mobile,
					captcha:this.form.code,
					newpassword:this.form.newpassword
				}
				if(this.form.newpassword==this.form.newpassword1){
					resetPwd(data).then(res=>{
						console.log(res);
						uni.navigateTo({
							url:'/pages/user/login'
						})
					})
				}else{
					uni.showToast({
						icon:'error',
						title:'密码不一致'
					})
				}
			},
			getCode(){
				if (this.form.mobile == "") {
					uni.showToast({
						icon: 'error',
						title: '请先填写手机号'
					})
					return
				}
				let data = {
					mobile:this.form.mobile,
					event:'resetpwd',
					usertype:1
				}
				getCodes(data).then(res=>{
						console.log(res)
						this.debonce()
					})
				
				
			},
			debonce() {
				this.dis = true
				let p = setInterval(() => {
					this.wait--
					if (this.wait === 0) {
						this.dis = false
						this.wait = 60;
						clearInterval(p)
					}
				}, 1000)
			},
		}
	}
</script>

<style scoped lang="scss">
	.resetpwd_page {
		width: 100vw;
		height: 100vh;
		padding: 32rpx;
		box-sizing: border-box;
		background-color: #FAFAFA;
	}

	.page_content {
		width: 100%;
		height: 460rpx;
		border-radius: 8rpx;
		padding: 0rpx 32rpx;
		box-sizing: border-box;
		background-color: #FFFFFF;
	}

	.code_btn {
		width: 170rpx;
		height: 56rpx;
		font-size: 20rpx;
		line-height: 56rpx;
		color: #FFFFFF;
		text-align: center;
		background: rgba(0, 204, 123, 0.3);
		border-radius: 82rpx;
	}

	.items {
		height: 100rpx;
		// background-color: red;
		border-bottom: 2rpx #FAFAFA solid;
	}

	.sumbit_btn {
		width: 100%;
		height: 88rpx;
		border-radius: 74rpx;
		color: #FFFFFF;
		background-color: #00CC7B;
		font-size: 32rpx;
		font-weight: bold;
		margin-top: 112rpx;
	}
</style>